package com.dianping.cat.consumer.all.config.transform;

import com.dianping.cat.consumer.all.config.IEntity;
import com.dianping.cat.consumer.all.config.IVisitor;
import com.dianping.cat.consumer.all.config.entity.AllConfig;
import com.dianping.cat.consumer.all.config.entity.Name;
import com.dianping.cat.consumer.all.config.entity.Report;
import com.dianping.cat.consumer.all.config.entity.Type;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private AllConfig m_allConfig;


  public DefaultMerger() {}

  public DefaultMerger(AllConfig allConfig) {
/*  22 */     this.m_allConfig = allConfig;
/*  23 */     this.m_objs.push(allConfig);
  }


/*  27 */   public AllConfig getAllConfig() { return this.m_allConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }


/*  41 */   protected void mergeAllConfig(AllConfig to, AllConfig from) { to.mergeAttributes(from); }



/*  45 */   protected void mergeName(Name to, Name from) { to.mergeAttributes(from); }



/*  49 */   protected void mergeReport(Report to, Report from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeType(Type to, Type from) { to.mergeAttributes(from); }



  public void visitAllConfig(AllConfig from) {
/*  58 */     AllConfig to = (AllConfig)this.m_objs.peek();

/*  60 */     mergeAllConfig(to, from);
/*  61 */     visitAllConfigChildren(to, from);
  }

  protected void visitAllConfigChildren(AllConfig to, AllConfig from) {
/*  65 */     for (Report source : from.getReports().values()) {
/*  66 */       Report target = to.findReport(source.getId());

/*  68 */       if (target == null) {
/*  69 */         target = new Report(source.getId());
/*  70 */         to.addReport(target);
      }

/*  73 */       this.m_objs.push(target);
/*  74 */       source.accept(this);
/*  75 */       this.m_objs.pop();
    }
  }


  public void visitName(Name from) {
/*  81 */     Name to = (Name)this.m_objs.peek();

/*  83 */     mergeName(to, from);
/*  84 */     visitNameChildren(to, from);
  }


  protected void visitNameChildren(Name to, Name from) {}


  public void visitReport(Report from) {
/*  92 */     Report to = (Report)this.m_objs.peek();

/*  94 */     mergeReport(to, from);
/*  95 */     visitReportChildren(to, from);
  }

  protected void visitReportChildren(Report to, Report from) {
/*  99 */     for (Type source : from.getTypes().values()) {
/* 100 */       Type target = to.findType(source.getId());

/* 102 */       if (target == null) {
/* 103 */         target = new Type(source.getId());
/* 104 */         to.addType(target);
      }

/* 107 */       this.m_objs.push(target);
/* 108 */       source.accept(this);
/* 109 */       this.m_objs.pop();
    }
  }


  public void visitType(Type from) {
/* 115 */     Type to = (Type)this.m_objs.peek();

/* 117 */     mergeType(to, from);
/* 118 */     visitTypeChildren(to, from);
  }

  protected void visitTypeChildren(Type to, Type from) {
/* 122 */     for (Name source : from.getNameList()) {
/* 123 */       Name target = null;

/* 125 */       if (target == null) {
/* 126 */         target = new Name();
/* 127 */         to.addName(target);
      }

/* 130 */       this.m_objs.push(target);
/* 131 */       source.accept(this);
/* 132 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/all/config/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */